<template>
	<view class="login">
		<image class="login-image" :src="logo">

		</image>
		<button :class="checkboxValue==true ?'login-btn':'login-disabled'" open-type="getPhoneNumber"
			@getphonenumber="decryptPhoneNumber" :disabled="checkboxValue==true ? false :true">微信登录</button>
		<view class="login-check">
			<checkbox-group @change="change">
				<checkbox activeBackgroundColor="#06B465" :value="checkboxValue1" activeBorderColor="#06B465"
					checked="checkboxValue1" style="transform:scale(0.7)">
				</checkbox>
			</checkbox-group>
			<view style="display: flex;flex-wrap: wrap;margin-top: 4rpx;">
				<view style="width: 214rpx;">
					我已阅读同意并同意
				</view>
				<view class="xy" @click="toAgree()">《***协议》</view>
				<view class="xy" @click="toAgree(2)">《用户协议》</view>
				<view class="xy" @click="toAgree(1)">《隐私协议》</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		LoginLogo,
		ApiWxlogin,
		UserOpenId
	} from '../../api/login.js'
	export default {
		data() {
			return {
				logo: "",
				checkboxValue: true,
				checkboxValue1: true,
			}
		},
		created() {
			// uni.removeStorageSync('Token')
			this.getLogo()
		},
		methods: {
			change(e) {
				console.log(e.detail.value[0] == "true")
				if (e.detail.value[0] == "true") {
					this.checkboxValue = true
				} else {
					this.checkboxValue = false
				}
			},
			async getLogo() {
				const {
					data
				} = await LoginLogo()
				console.log(data.data.logo)
				this.logo = data.data.logo
			},
			async decryptPhoneNumber(e) {
				console.log(e.detail, '---43---')
				const data = await ApiWxlogin({
					code: e.detail.code,
					encryptedData: e.detail.encryptedData,
					iv: e.detail.iv
				})
				console.log(data, '---50---')
				if (data.statusCode == 200) {
					uni.setStorageSync('Token', data.data.data.token)
					uni.login({
						provider: 'weixin', //使用微信登录
						success: async function(loginRes) {
							const data = await UserOpenId(loginRes.code)
						}
					});
					if (data.data.data.is_info == 1) {
						uni.switchTab({
							url: '/pages/index/index'
						})
					} else {
						uni.navigateTo({
							url: '/pages/wxlogin/index'
						})
					}
				}

			},
			toAgree(id) {
				uni.navigateTo({
					url: '/pages/agreementDetail/index?id=' + id
				})
			}


		}
	}
</script>

<style lang="scss" scoped>
	.login {
		.login-image {
			width: 424rpx;
			height: 424rpx;
			// background-color: red;
			margin-left: 164rpx;
			margin-top: 252rpx;
		}

		.login-btn {
			width: 370rpx;
			height: 96rpx;
			background: linear-gradient(90deg, #EC8D7E 0%, #FF6F59 100%);
			box-shadow: 0rpx 4rpx 20rpx 0rpx #F7E4E1, inset 0rpx 2rpx 20rpx 6rpx rgba(255, 174, 161, 0.61);
			border-radius: 48rpx;
			font-size: 32rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 110rpx;
		}

		.login-disabled {
			width: 370rpx;
			height: 96rpx;
			background: #ccc;
			border-radius: 48rpx;
			font-size: 32rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 110rpx;
		}

		.login-check {
			width: 590rpx;
			// height: 68rpx;
			margin-left: 80rpx;
			margin-top: 584rpx;
			display: flex;
			align-items: flex-start;
			font-size: 24rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.35);
			line-height: 34rpx;
			// flex-wrap: wrap;
		}

		.xy {
			color: #5861C0;
		}
	}
</style>